package com.hzspace.counter;

/**
 * @Author: LiuHao
 * @Descirption:
 * @Date: 2019/6/14_15:38
 */
public class Counter3 {

    private int count;

    public void add(){
        try{
            for(int i=0; i<200; i++){
                Thread.sleep(100);
                synchronized (this){
                    this.count++;//竞争条件
                    System.out.println(this.count);
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
